Page({
  data: {
    name: '',
    contact: '',
    description: '',
    textareaLength: 0
  },

  onLoad() {
    // 初始化页面数据
    this.setData({
      name: '',
      contact: '',
      description: '',
      textareaLength: 0
    });
  },
  
  onNameInput(e) {
    this.setData({
      name: e.detail.value
    });
  },

  onContactInput(e) {
    this.setData({
      contact: e.detail.value
    });
  },

  onDescriptionInput(e) {
    this.setData({
      description: e.detail.value,
      textareaLength: e.detail.value.length
    });
  },

  submitFeedback() {
    const { name, contact, description } = this.data;

    // 验证表单数据
    if (!name) {
      wx.showModal({
        title: '提示',
        content: '请输入您的姓名',
        showCancel: false
      });
      return;
    }

    if (!contact) {
      wx.showModal({
        title: '提示',
        content: '请输入您的联系方式',
        showCancel: false
      });
      return;
    }

    if (!description) {
      wx.showModal({
        title: '提示',
        content: '请描述您遇到的问题',
        showCancel: false
      });
      return;
    }

    // 提交反馈
    wx.showLoading({
      title: '正在提交...'
    });

    // 模拟提交反馈的异步操作
    setTimeout(() => {
      wx.hideLoading();
      wx.showToast({
        title: '反馈提交成功',
        icon: 'success'
      });

      // 清空表单数据
      this.setData({
        name: '',
        contact: '',
        description: '',
        textareaLength: 0
      });
    }, 2000);

    wx.switchTab({
      url: 'pages\my\my',
    })
  }
});
